const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('sys_app', {
    id: {
      type: DataTypes.STRING(50),
      allowNull: false,
      primaryKey: true
    },
    app_name: {
      type: DataTypes.STRING(50),
      allowNull: false,
      comment: "应用名称，网关消费者。全小写，由两个部分组成 [产品]和[端类型]，中间用下杠链接。",
      unique: "uniq_app_name"
    },
    app_desc: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "应用描述"
    },
    app_key: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: "应用app_key"
    },
    app_secret: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: "应用app_secret"
    },
    app_user_type: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "应用中用户对应的类型，1-管理员，2-第三方机构人员，3-监管人员，4-社会单位人员，可以同时有多个类型，多个用,号隔开"
    },
    services: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "可访问网关服务配置"
    },
    is_enable: {
      type: DataTypes.TINYINT,
      allowNull: true,
      defaultValue: 1
    },
    is_delete: {
      type: DataTypes.TINYINT,
      allowNull: true,
      defaultValue: 0
    },
    created_at: {
      type: DataTypes.DATE,
      allowNull: true,
      defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
    },
    deleted_at: {
      type: DataTypes.DATE,
      allowNull: true
    }
  }, {
    sequelize,
    tableName: 'sys_app',
    timestamps: false,
    freezeTableName: true,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
      {
        name: "uniq_app_name",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "app_name" },
        ]
      },
    ]
  });
};
